// 引入env中的url
const baseUrl = `https://api.scf.moapp.net.cn/release/mocha_exam_wxapp/result`;

module.exports = {
    /**二次封装wx.request()
     * method:请求方式
     * data传参
     * */
    request: (baseUrl, method = 'POST', queryData, header) => {
        return new Promise((resolve, reject) => {
            wx.request({
                url: baseUrl,
                method: method,
                data: queryData,
                header: {
                    'content-type': 'application/json',
                    ...header
                },
                success: (res) => {
                    if (res.data.code === 'OK' || res.data.code === 'SUCCESS') {
                        resolve(res.data.data);
                    } else {
                        reject({ msg: res.data.msg || res.data.errorMessage });
                    }
                },
                fail: (err) => {
                    reject(err);
                }
            });
        });
    }
};
